﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Diagnostics;
using TomanuExtensions;

namespace AmiEmuLib.Render.Filter.SoftwareFilter
{
    /// <summary>
    /// List of software filters.
    /// </summary>
    [DebuggerDisplay("Count = {Count}")]
    public static class SoftwareFilters
    {
        /// <summary>
        /// List of software filters.
        /// </summary>
        private static List<SoftwareFilter> m_filters = new List<SoftwareFilter>();

        /// <summary>
        /// Static constructor.
        /// </summary>
        static SoftwareFilters()
        {
            var toadd = from type in Assembly.GetAssembly(typeof(SoftwareFilters)).GetTypes()
                        where type.IsClass
                        where !type.IsAbstract
                        where type.IsDerivedFrom(typeof(SoftwareFilter))
                        select (SoftwareFilter)Activator.CreateInstance(type);

            m_filters.AddRange(toadd.OrderBy(f => f.Name));
        }

        /// <summary>
        /// List of software filters.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<SoftwareFilter> Filters
        {
            get
            {
                return m_filters;
            }
        }

        /// <summary>
        /// Get filter by name.
        /// </summary>
        /// <param name="a_name"></param>
        /// <returns></returns>
        public static SoftwareFilter GetFilter(string a_name)
        {
            return m_filters.First(f => f.Name == a_name);
        }
    }
}
